package com.modules.controller.sys;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.controller.MyController;
import com.common.log.LogData;
import com.common.vo.LoginUser;
import com.common.vo.Result;
import com.modules.entity.sys.DeptEntity;
import com.modules.service.sys.DeptService;


/**
 * 部门
 * @author yyq
 *
 */
@Controller
@RequestMapping("/sys/dept")
public class DeptController extends MyController<DeptEntity>{

	@Autowired
	private DeptService service;
	
	/**
	 * 查询
	 * @param dept
	 * @return
	 */
	@RequestMapping("/select")
	@ResponseBody
	public Result<?> select(DeptEntity dept){
		LoginUser u = getUser();
		if (dept.getOid() == null) {
			dept.setOid(u.getLastOid());
		}
		return service.select(dept);
	}

	@RequestMapping("/selectTree2")
	@ResponseBody
	public Result<?> selectTree2(DeptEntity dept){
		LoginUser u = getUser();
		if (dept.getOid() == null) {
			dept.setOid(u.getLastOid());
		}
		return service.select(dept);
	}
	/**
	 * 查询
	 * @param dept
	 * @return
	 */
	@RequestMapping("/selectOne")
	@ResponseBody
	public Result<?> selectOne(DeptEntity dept){
		return service.selectOne(dept);
	}

	/**
	 * 保存
	 * @param dept
	 * @return
	 */
	@RequestMapping("/save")
	@ResponseBody
	public Result<?> save(DeptEntity dept){
		return service.save(dept);
	}
	
	/**
	 * 删除
	 * @return
	 */
	@LogData(module = "部门管理", remarks = "删除单个")
	@RequestMapping("/delete")
	@ResponseBody
	public Result<?> delete(DeptEntity dept){
		return service.delete(dept.getDid());
	}

	/**
	 * 获取当前组的所有
	 * @param dept
	 * @return
	 */
	@RequestMapping("/selectBranch")
	@ResponseBody
	public Result<?> selectBranch(DeptEntity dept){
		LoginUser u = getUser();
		if (dept.getOid() == null) {
			dept.setOid(u.getLastOid());
		}
		return service.selectBranch(dept);
	}

	/**
	 * 获取当前组的所有
	 * @param dept
	 * @return
	 */
	@RequestMapping("/selectTop")
	@ResponseBody
	public Result<?> selectTop(DeptEntity dept){
		LoginUser u = getUser();
		if (dept.getOid() == null) {
			dept.setOid(u.getLastOid());
		}
		return service.selectTop(dept);
	}

}
